package org.theSeed.base.utils;

import org.theSeed.base.pojo.constant.TimeZoneConstant;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 时间转换工具
 */
public class DateTransUtil {
    /**
     * date转LocalDateTime
     * @param date
     * @return
     */
    public static LocalDateTime dateToLocalDateTime(Date date){
        return date.toInstant()
                .atZone(TimeZoneConstant.getSysZone())
                .toLocalDateTime();
    }

    /**
     * date转LocalDate
     * @param date
     * @return
     */
    public static LocalDate dateToLocalDate(Date date){
        return date.toInstant()
                .atZone(TimeZoneConstant.getSysZone())
                .toLocalDate();
    }

    /**
     * date转LocalDate
     * @param localDateTime
     * @return
     */
    public static Date localDateTimeToDate(LocalDateTime localDateTime){
        return Date.from(localDateTime.atZone(TimeZoneConstant.getSysZone()).toInstant());
    }

    /**
     * date转LocalDate
     * @param localDate
     * @return
     */
    public static Date localDateToDate(LocalDate localDate){
        return Date.from(localDate.atStartOfDay(TimeZoneConstant.getSysZone()).toInstant());
    }
}
